﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharpSoft.WPF.Video
{
    /// <summary>
    /// PlayerPlayButton.xaml 的交互逻辑
    /// </summary>
    public partial class PlayerPlayButton : CheckBox
    {
        public PlayerPlayButton()
        {
            InitializeComponent();
        }
        protected override void OnChecked(RoutedEventArgs e)
        {
            base.OnChecked(e);
            RelevanceMeidaElement?.Play();
        }
        protected override void OnUnchecked(RoutedEventArgs e)
        {
            base.OnUnchecked(e);
            RelevanceMeidaElement?.Pause();
        }

        private MediaElement _RelevanceMeidaElement;
        /// <summary>
        /// 获取或设置关联的媒体控件
        /// </summary>
        public MediaElement RelevanceMeidaElement
        {
            get { return _RelevanceMeidaElement; }
            set
            {
                _RelevanceMeidaElement = value;
                if (_RelevanceMeidaElement != null)
                {
                    _RelevanceMeidaElement.MediaEnded += _RelevanceMeidaElement_MediaEnded;
                }
            }
        }

        private void _RelevanceMeidaElement_MediaEnded(object sender, RoutedEventArgs e)
        {
            RelevanceMeidaElement?.Stop();
            this.IsChecked = false;
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {

        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {

        }
    }
}
